<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>TCP BBR 设置及其增强版</title>
  
    <meta name="author" content="jouyouyun">

    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le styles -->
    <link href="/assets/twitter/stylesheets/bootstrap.min.css" type="text/css" rel="stylesheet" media="all">
<link href="/assets/twitter/stylesheets/style.css" type="text/css" rel="stylesheet" media="all">
<link href="/assets/twitter/widgets/google_prettify/stylesheets/twitter-bootstrap.css" type="text/css" rel="stylesheet" media="all">
 

    <!-- Le fav and touch icons -->
  <!-- Update these with your own images
    <link rel="shortcut icon" href="images/favicon.ico">
    <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
  -->
  </head>

  <body>

    <div class="navbar">
      <div class="navbar-inner">
        <div class="container">
          <a class="brand" href="/">Jouyouyun&#39;s Blog</a>
          <ul class="nav">
            
              


  <li><a href="/archive">Archive</a></li>


            
              


  <li><a href="/tags">Tags</a></li>


            
              


  <li><a href="/categories">Categories</a></li>


            
              


  <li><a href="/about">About Me</a></li>


            
          </ul>
        </div>
      </div>
    </div>

    <div class="container">

      <div class="content">
        <div class="page-header">
  <h1>TCP BBR 设置及其增强版 </h1>
</div>

<div class="row">
  <div class="span8">
    <h3>启用 BBR</h3>

<p><code>BBR</code> 是在 4.9 以后的内核才开始支持的, 可以试着执行 <code>sudo modprobe tcp_bbr</code> 来确定是否支持, 没有输出就意味着支持, 将下面两行内容添加到 <code>/etc/sysctl.conf</code> 文件里开启用它:</p>

<pre><code class="language-shell">net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
</code></pre>

<p>使用 <code>sysctl net.ipv4.tcp_available_congestion_control</code> 查看支持的算法, 用<code>sysctl net.ipv4.tcp_congestion_control</code> 查看当前使用的算法.</p>

<p>如果这个模块不会自动加载, 需要把 <code>tcp_bbr_powered</code> 添加到 <code>/etc/modules-load.d/modules.conf</code> 中.
另外测试发现, 有时 <code>sysctl.conf</code> 里的设置并不会应用, 需要手动执行一下, 因此便写了 <code>reload-sysctl.service</code> 来做这个, <code>systemctl enable</code> 这个服务后, 一切就 OK 了.</p>

<hr />

<h3>使用增强版</h3>

<p>个人电脑不建议使用增强版, 服务器上可以使用, 当然最终还是要根据两者的效果来选择.</p>

<p>来源于: <a href="https://moeclub.org/2017/06/24/278/">Debian/Ubuntu TCP BBR 改进版/增强版</a></p>

<ul>
<li><p>Build</p>

<pre><code class="language-shell">$ ./build.sh
</code></pre></li>

<li><p>Install</p>

<pre><code class="language-shell">$ ./install.sh
</code></pre></li>

<li><p>Clean</p>

<pre><code class="language-shell">$ rm Makefile tcp_bbr_powered.*
</code></pre></li>
</ul>

<p>使用 <code>sysctl net.ipv4.tcp_available_congestion_control</code> 查看支持的算法, 用<code>sysctl net.ipv4.tcp_congestion_control</code> 查看当前使用的算法.</p>

<p>如果这个模块不会自动加载, 需要把 <code>tcp_bbr_powered</code> 添加到 <code>/etc/modules-load.d/modules.conf</code> 中.
另外测试发现, 有时 <code>sysctl.conf</code> 里的设置并不会应用, 需要手动执行一下, 因此便写了 <code>reload-sysctl.service</code> 来做这个, <code>systemctl enable</code> 这个服务后, 一切就 OK 了.</p>

<hr />

<h3>附件</h3>

<ul>
<li><p>build.sh</p>

<pre><code class="language-shell">wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxSoftware/bbr/tcp_bbr_powered.c.deb' &gt;./tcp_bbr_powered.c
echo 'obj-m:=tcp_bbr_powered.o' &gt;./Makefile
echo 'clean: ' &gt;&gt; ./Makefile
echo -e '\trm -r Module.symvers modules.order tcp_bbr_powered.mod.* tcp_bbr_powered.o .tcp_bbr_powered.* .tmp_versions' &gt;&gt; ./Makefile

make -s -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=`which gcc`
make clean
</code></pre></li>

<li><p>install.sh</p>

<pre><code class="language-shell">[ -f ./tcp_bbr_powered.ko ] &amp;&amp; [ -f /lib/modules/$(uname -r)/modules.dep ] &amp;&amp; {
cp -rf ./tcp_bbr_powered.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a &gt;/dev/null 2&gt;&amp;1                 
}                                         

# configure
modprobe tcp_bbr_powered
[ ! -f /etc/sysctl.conf ] &amp;&amp; touch /etc/sysctl.conf                                 
sed -i '/net.core.default_qdisc.*/d' /etc/sysctl.conf                               
sed -i '/net.ipv4.tcp_congestion_control.*/d' /etc/sysctl.conf                      
echo &quot;net.core.default_qdisc = fq&quot; &gt;&gt;/etc/sysctl.conf                               
echo &quot;net.ipv4.tcp_congestion_control = bbr_powered&quot; &gt;&gt;/etc/sysctl.conf             

lsmod |grep -q 'bbr_powered'              
[ $? -eq '0' ] &amp;&amp; {                       
sysctl -p &gt;/dev/null 2&gt;&amp;1                 
echo &quot;Finish! &quot;                           
exit 0                                    
} || {                                    
echo &quot;Error, Loading BBR POWERED.&quot;        
exit 1                                    
}
</code></pre></li>

<li><p>reload-sysctl.service</p>

<pre><code class="language-shell">[Unit]
Description=Reload sysctl
Before=network.target

[Service]
Type=simple
ExecStart=/usr/bin/sysctl -p

[Install]
WantedBy=multi-user.target
</code></pre></li>
</ul>

    <hr>
    <div class="pagination">
      <ul>
        <ul>
          
            <li class="prev"><a href="/Blog/%E8%AE%BE%E7%BD%AE-Grub2-%E5%88%86%E8%BE%A8%E7%8E%87/" title="设置 Grub2 分辨率">&larr; Previous</a></li>
          
          

            <li><a href="/archive">Archive</a></li>

          
            <li class="next"><a href="/Blog/Leanote-Install/" title="Leanote Install">Next &rarr;</a></li>
          
          
        </ul>
      </ul>
    </div>
    <hr>
    
<div id="disqus_thread"></div>
<script>
    var disqus_developer = 1;
    var disqus_shortname = 'jekyllbootstrap'; // required: replace example with your forum shortname
    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>

  </div>
  
  <div class="span4">
    <h4>Published</h4>
    <div class="date"><span>2017-07-20</span></div>
    <br>
    <h4>Categories</h4>
    <ul class="tag_box">
    
      <li>
  <a href="/categories/#Blog-ref">Blog <span>23</span></a>
</li>
    
    </ul>
    <br>
    <h4>Tags</h4>
    <ul class="tag_box">
    
      <li>
  <a href="/tags/#tcp-ref">tcp <span>2</span></a>
</li>
    
      <li>
  <a href="/tags/#bbr-ref">bbr <span>1</span></a>
</li>
    
    </ul>
  </div>
</div>

      </div>

      <footer>
        <p>&copy; jouyouyun 2013 
          with help from <a href="http://github.com/wendal/gor" target="_blank" title="Gor -- Fast Blog">Gor</a>
          and <a href="http://twitter.github.com/bootstrap/" target="_blank">Twitter Bootstrap</a>
		  and Idea from <a href="http://ruhoh.com" target="_blank" title="The Definitive Technical Blogging Framework">ruhoh</a>
        </p>
      </footer>

    </div> <!-- /container -->

    
<script src="//cdnjscn.b0.upaiyun.com/libs/prettify/r298/prettify.min.js"></script>
<script>
  var pres = document.getElementsByTagName("pre");
  for (var i=0; i < pres.length; ++i) {
    pres[i].className = "prettyprint linenums";
  }
  prettyPrint();
</script>

    
<script type="text/javascript">

  var _gaq = _gaq || [];
  var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
  _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
  _gaq.push(['_setAccount', 'UA-123-12']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
  </body>
</html>
